package com.fyzk.activity.lottery.recommend_order;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.fyzk.base.BaseActivity;
import com.fyzk.activity.app.AppToast;
import com.tyjc.lottery.R;
import com.fyzk.net.Commands;
import com.fyzk.view.RefreshListView;
import com.fyzk.view.TopTitleView;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import http.Common.CommandUtil;
import http.StringResultBean;

/**
 * Created by fanxs11 on 17/7/4.
 * 晒单——普通大神
 */

@ContentView(R.layout.ac_certificationgod)
public class GeneralGodActivity extends BaseActivity implements RefreshListView.OnRefreshListener {

    @ViewInject(R.id.certificationgod_topview)
    private TopTitleView topView;

    @ViewInject(R.id.certificationgod_listview)
    private RefreshListView listView;
    private List<GodBean> infos = new ArrayList<>();
    private GodAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

        findRecommendGodRanking(true);
    }

    private void initView() {
        topView.setOnTitleClickListener(this);
        topView.setCenterText("普通大神");

        listView.setItemsCanFocus(false);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnRefreshListener(this);
        adapter = new GodAdapter(getContext(), infos);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (listView.isDownPull){
                    return;
                }
                Intent intent = new Intent(getContext(), HisCenterActivity.class);
                startActivity(intent);
                if (i > 0 && i <= infos.size()) {
                    AppToast.getToast().show("点击："+i);
//                    Intent intent = new Intent(getContext(), TopicDetailActivity.class);
//                    intent.putExtra("id", infos.get(i - 1).getQuestion_id());
//                    startActivity(intent);
                }

            }
        });
    }

    /**
     * 查询普通大神榜
     * @param showProgress
     */
    private void findRecommendGodRanking(boolean showProgress) {
        JSONObject request_json = new JSONObject();
        try {
            request_json.put("raceType", 1);    // 类型（竞彩足球：0；竞彩篮球：1）
            httpPostJson(CommandUtil.FINDRECOMMENDPOWERRANKING, Commands.FINDRECOMMENDGODRANKING, request_json,
                    showProgress);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onSuccess(int requestCode, StringResultBean resultBean, String result) {
        super.onSuccess(requestCode, resultBean, result);

    }

    @Override
    protected void onFailure(int requestCode, String errorCode, String message) {
        super.onFailure(requestCode, errorCode, message);

    }

    @Override
    public void onDownPullRefresh() {

    }

    @Override
    public void onLoadingMore() {

    }
}
